package com.funong.matrix.biz.base.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.funong.matrix.biz.base.entity.SysLogEntity;
import com.funong.matrix.biz.base.mapper.SysLogMapper;
import com.funong.matrix.biz.system.pojo.qo.SysLogQO;
import com.funong.matrix.core.base.Dao;
import com.funong.matrix.core.base.FunongBaseDao;
import com.funong.matrix.core.dto.QueryDTO;
import com.funong.matrix.core.enums.IsDeletedEnum;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.annotation.Aspect;

/**
 * @author : NaNa
 * @since : 2023-05-19 16:42
 **/
@Aspect
@Dao
public class SysLogDao extends FunongBaseDao<SysLogMapper, SysLogEntity> {

    public IPage<SysLogEntity> queryLogByCondition(QueryDTO<SysLogQO> queryDTO) {
        SysLogQO logQO = queryDTO.getCondition();
        return this.page(new Page<>(queryDTO.getPageNo(), queryDTO.getPageSize()), new LambdaQueryWrapper<SysLogEntity>()
                .eq(null != logQO && null != logQO.getOperator(), SysLogEntity::getOperator, logQO.getOperator())
                .eq(null != logQO && StringUtils.isNotBlank(logQO.getBizModule()), SysLogEntity::getBizModule, logQO.getBizModule())
                .eq(null != logQO && StringUtils.isNotBlank(logQO.getBizCode()), SysLogEntity::getBizCode, logQO.getBizCode())
                .ge(null != logQO && StringUtils.isNotBlank(logQO.getBeginDay()), SysLogEntity::getCreatedAt, logQO.getBeginDay())
                .le(null != logQO && StringUtils.isNotBlank(logQO.getEndDay()), SysLogEntity::getCreatedAt, logQO.getEndDay())
                .eq(SysLogEntity::getIsDeleted, IsDeletedEnum.NOT_DELETED.getValue()));
    }
}
